home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Stat.ced
- **
- ** $VER: Stat.ced 1.4 (14.1.95)
- **
- ** This scripts displays current file's statistics: number of chars, lines,
- ** words and sentences. ARexx'es definition of word is used, not CEd's.
- ** Sentences are counted by checking number of '.', '!' and '?' chars.
- ** This script works much faster than ASDG's Word-Count-File.ced.
- ** To get statistics for whole file just call this script. To get statistics
- ** for part of file, mark a block and call this macro.
- ** See docs for more details.
- **
- ** This script requires CygnusEd Professional v3.5 (or later) to run.
- **
- ** Copyright © 1995 Michael Letowski
- */
-
- /* Get host */
- PARSE SOURCE com res called resolved ext host .
- IF host="REXX" THEN /* From command line */
- ADDRESS "rexx_ced" /* Talk to default ced */
-
- OPTIONS RESULTS /* Enable results from commands */
-
- LF='0A'X /* Simple constant */
-
- 'Status CURSORCOLUMN' /* Get cursor horizontal... */
- Column=RESULT+1
- 'Status CURSORLINE' /* ... and vertical position */
- Line=RESULT+1
-
- 'DM "Copying to clipboard..."' /* Let the user know what's going on */
-
- 'Copy block' /* Something selected yet? */
- IF ~RESULT THEN
- DO
- 'Beg of file' /* Copy whole file to clipboard */
- 'Mark block'
- 'End of file'
- 'Copy block'
- END
-
- 'LL' Line Column /* Move cursor to old position */
- 'DM "Counting..."' /* Change status bar again */
-
- 'Status RESTNAME' /* Get file name */
- FileName=RESULT
- 'Status BLOCKBUFFER' /* Get text from clipboard */
- Res=RESULT
-
- WordsInText=Words(Res) /* Count words */
- TotalLen=Length(Res) /* Calculate size of buffer */
- StripLen=Length(Compress(Res,".!?")) /* Delete punctuations from text */
- LinesLen=Length(Compress(Res,LF)) /* Delete LFs from text */
- Sentences=TotalLen-StripLen /* Substract to get number of sentences */
- FileLines=TotalLen-LinesLen+1 /* Substract to get number of lines */
-
- IF TotalLen=1 THEN TotalLen=TotalLen "char"
- ELSE TotalLen=TotalLen "chars"
-
- IF FileLines=1 THEN FileLines=FileLines "line"
- ELSE FileLines=FileLines "lines"
-
- IF WordsInText=1 THEN WordsInText=WordsInText "word"
- ELSE WordsInText=WordsInText "words"
-
- IF Sentences=1 THEN Sentences=Sentences "sentence"
- ELSE Sentences=Sentences "sentences"
-
- Header="Text statistics for" "'"FileName"':"
- HdrLen=Length(Header)
- OutputText=Header||LF
- OutputText=OutputText||CENTRE(TotalLen,HdrLen)||LF
- OutputText=OutputText||CENTRE(FileLines,HdrLen)||LF
- OutputText=OutputText||CENTRE(WordsInText,HdrLen)||LF
- OutputText=OutputText||CENTRE(Sentences,HdrLen)
-
- 'Okay1' OutputText /* Present results to user */
- 'DM' /* Restore status line */
-
- EXIT
-